/**
 * 易码当先 <br>
 * Hadoop-mr <br>
 * cc.ic2c.hadoop.mr <br>
 * FlowBean.java <br>
 * @author Allister.Liu(刘继鹏) <br>
 * Email：laujip@163.com <br>
 * 时间：2017年11月14日-下午8:45:56 <br>
 * 2017Allister-版权所有 <br>
 */
package cc.ic2c.hadoop.mr;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

/**
 * <br>
 * FlowBean <br>
 * 
 * @author Allister.Liu(刘继鹏) <br>
 *         Email：laujip@163.com <br>
 *         时间：2017年11月14日-下午8:45:56 <br>
 * @version 1.0.0
 * 
 */
public class FlowBean implements WritableComparable<FlowBean> {

	private String phoneNo;
	private long upFlow;
	private long dFlow;
	private long sumFlow;

	public void set(String phoneNo, long upFlow, long dFlow) {

		this.phoneNo = phoneNo;
		this.upFlow = upFlow;
		this.dFlow = dFlow;
		this.sumFlow = dFlow + dFlow;

	}

	

	public String getPhoneNo() {
		return phoneNo;
	}



	public void setPhoneNo(String phoneNo) {
		this.phoneNo = phoneNo;
	}



	public long getUpFlow() {
		return upFlow;
	}



	public void setUpFlow(long upFlow) {
		this.upFlow = upFlow;
	}



	public long getdFlow() {
		return dFlow;
	}



	public void setdFlow(long dFlow) {
		this.dFlow = dFlow;
	}



	public long getSumFlow() {
		return sumFlow;
	}



	public void setSumFlow(long sumFlow) {
		this.sumFlow = sumFlow;
	}



	/**
	 * 序列化，将数据字段以字节流写出去
	 */
	@Override
	public void write(DataOutput out) throws IOException {

		out.writeUTF(phoneNo);
		out.writeLong(upFlow);
		out.writeLong(dFlow);
		out.writeLong(sumFlow);

	}

	/**
	 * 反序列化，从字节流中读出各个数据字段 读出的顺序应该跟序列化时写入的顺序保持一致
	 */
	@Override
	public void readFields(DataInput in) throws IOException {
		phoneNo = in.readUTF();
		upFlow = in.readLong();
		dFlow = in.readLong();
		sumFlow = in.readLong();
	}

	@Override
	public String toString() {

		return upFlow + "\t" + dFlow + "\t" + sumFlow;
	}

	@Override
	public int compareTo(FlowBean o) {

		return sumFlow > o.getSumFlow() ? -1 : 1;
	}

}
